<!DOCTYPE html>
<html>
<head>
    {include file="public/head" /}
<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script></head>
<body>
<div class="Tbox active">
    <div class="mask"></div>
    <div class="show cor">
        <div class="Oauth">
            <div class="title-box tc lh30 bsilk fs10">
                <h1>手机验证</h1>
            </div>
            <div class="form sign">
                <form action="">
                    <input type="hidden" name="headimgurl" value="{:input('headimgurl')}" />
                    <input type="hidden" name="nickname" value="{:input('nickname')}" />
                    <input type="hidden" name="openid" value="{:input('openid')}" />

                    <div class="cell icons bsilk">
                        <span class="fa fa-phone pabs-l-box"></span>
                        <input type="number" name="mobile" placeholder="请输入您的手机号码">
                        <select class="pabs-r-box" name="areacode">
                            <option value="+86" disabled>+86</option>
                            <option value="">+86</option>
<!--                            <option>+86</option>-->
<!--                            <option>+86</option>-->
<!--                            <option>+86</option>-->
<!--                            <option>+86</option>-->
                        </select>
                    </div>
                    <div class="cell icons code bsilk">
                        <span class="fa fa-envelope-o pabs-l-box"></span>
                        <input type="text" name="captcha" placeholder="输入验证码">
                        <button type="button" class="pabs-r-box message" >发送验证码</button>
                    </div>
                    <div class="cell sub baise">
                        <input style="color: #fff;background:palevioletred" type="button" name="" value="登录" onclick="register()">
                    </div>
                    <div class="cell imark c-red lh16 sub">
                        <input type="checkbox" name="agree">同意协议，《服务协议，隐私政策》
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<style>
    .baise{ color: #fff;}
</style>
<script>

    var messagestatus = true;
    var messagetime = 60;
    $('body').on('click','.message',function () {
        if(messagestatus){
            messagestatus = false;
            var phone = $('[name="mobile"]').val();
            if(phone==''){
                layer.msg('请输入手机号');
                messagestatus = true;
                return false;
            }
            $.ajax({
                type: "POST", //用POST方式传输
                dataType: "json", //数据格式:JSON
                url: "{:url('captcha')}", //目标地址
                data: {'username':phone,'type':'mini_register'},
                async: false,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    messagestatus = true;
                    messagetime = 60;
                    $('.message').html('获取验证码');
                },
                success: function (data) {
                    if(data.code !== 200){
                        messagestatus = true;
                        messagetime = 60;
                        $('.message').html('获取验证码');
                        layer.msg(data.message);
                        return false;
                    }else{
                        $('.message').html(messagetime+'s');
                        message1=setInterval(function () {
                            messagetime--;
                            if(messagetime<0){
                                $('.message').html('获取验证码');
                                messagestatus = true;
                                messagetime = 60;
                                clearInterval(message1);
                            }else{
                                $('.message').html(messagetime+'s');
                            }
                        },1000);
                    }
                }
            });
        }
    })

    //绑定售价或
    function register() {

        // var has_on = $('[name="agree"]').value();
        // alert(has_on);
        // var param = $('form').serializeArray();
        // if(!has_on){
        //     layer.msg('请先阅读隐私政策和用户协议');return
        // }
        var param = $('form').serializeArray();
        console.log(param[3]['value']);
        // if(param[3]['value'] == 0){
        //     layer.msg('请选择单位');return;
        // }
        //$("input[name='agree']:checkbox").each(function() {

            if (!$("input[name='agree']").is(":checked")) {
                layer.msg('请勾选服务协议/隐私政策');
                return false;
            }
       // });
            $.ajax({
            type: "POST", //用POST方式传输
            dataType: "json", //数据格式:JSON
            url: "{:url('member/register')}", //目标地址
            data:param,
            async: false,
            success: function (data) {
                if(data.code == 200){ //注册成功
                    localStorage.setItem('mobile',data.data.mobile);
                    window.location.href = "{:url('Member/my')}";
                    // layer.msg(data.message);
                }else if(data.code == 201){
                    localStorage.setItem('mobile',data.data.mobile);
                    window.location.href = "{:url('Member/my')}";
                }else{
                    layer.msg(data.message);
                    return false;
                }
            }
        });
    }


</script>